package http_servlet_request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Creared with IntelliJ IDEA.
 * Description:通过getParameter方法通过name得到query string的value值
 * User:yxd
 * Date:2022-05-29
 * Time:18:28
 */
@WebServlet("/getParameter")
public class GetParameterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //构造一个形如/getParameter?userId=10&class=20的请求,通过name得到其value
        String userId = req.getParameter("userId");
        String classId = req.getParameter("classId");
        resp.getWriter().write("userId=" + userId + ",classId=" + classId);
    }
}
